package com.stock.controller;

import com.goods.enumeration.CodeEnumeration;
import com.goods.utils.Result;
import com.goods.utils.ResultUtils;
import com.stock.service.StockService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/stock")
@Api(tags = "库存管理")
public class StockController {

    /**
     * 枚举
     */
    @Autowired
    private StockService stockService;
    @ApiOperation("修改库存")
    @PostMapping("/reduceStock/{shopId}")
    public Result  reduceStock(@PathVariable("shopId") Integer shopId){
        System.out.println(1/0);
        Integer stock = stockService.reduceStock(shopId);
        if (stock > 0) {
            Result ok = ResultUtils.ok();
            return ok;
        }
        return  ResultUtils.error(CodeEnumeration.UPDATE_FAIL.getCode(),CodeEnumeration.UPDATE_FAIL.getMessage());
        }
    }


